const mongoose = require('mongoose');
const { Article } = require('../../model/article')
const {Classify} = require('../../model/classify')
const pagination = require('mongoose-sex-page');


module.exports = async (req, res) => {
        // page 指定当前页
    // size 指定每页显示的数据条数,5
    // display 指定客户端要显示的页码数量
    // console.log(req.query);
    var id = req.params.id
    var page = req.params.page
    try {
        var classify = await Classify.findOne({_id:id})
        var data = await pagination(Article).find({ class: id,status:true }).page(page).select('title cover about').size(7).exec()
    } catch (err) {
        return res.send({
            data: null,
            meta: {
                status: 400,
                msg: '请求失败'
            }
        })
    }
    data.classify=classify
    if (data == null) return res.send({
        data: null,
        meta: {
            status: 400,
            msg: '请求失败'
        }
    })
    res.send({
        data: data,
        meta: {
            status: 200,
            msg: '请求成功'
        }
    })

}